/*
 * @Description:main
 * @Author: HYH
 * @LastEditors: HYH
 * @LastEditTime: 2022-08-31 15:23:45
 */
import { createApp } from 'vue'
import App from './App.vue'
import store from '@/store'
import { initRouter } from '@/router'
import directives from '@/directives/index'
import provides from '@/provides'

// 组件
import components from '@/components/index'
import init from '@/config/init'
;(async () => {
  /**初始化系统配置**/
  // 1.全局变量 (app),语言包(lpk),Ajax,Tools定义
  // 2.异步加载基础模块的配置信息
  // 3.异步加载业务模块，并完成基本的初始化
  init()
  // ======================================================================

  // = 初始化UI
  const uiApp = createApp(App)
  // ======================================================================

  // = 注册全局组件
  for (const componentItem in components) {
    uiApp.component(componentItem, components[componentItem])
  }
  // ======================================================================

  // = 初始化状态管理与路由，并渲染根组件
  uiApp.config.globalProperties.app = window.app
  uiApp.config.globalProperties.Tools = window.Tools
  uiApp.config.globalProperties.lang = window.lang
  uiApp.config.globalProperties.Apis = window.Apis
  uiApp.config.globalProperties.Rules = window.Rules
  uiApp.config.globalProperties.viewImg = window.viewImg
  uiApp.config.globalProperties.mock = window.mock
  uiApp.config.globalProperties.Random = window.Random

  // ======================================================================

  // = 使用插件
  uiApp
    .use(store) /** pinia */
    .use(initRouter())
    .use(directives)
    .use(provides)
    // = 页面挂载
    .mount('#app')
})()
